 
//BACKGROUND CHANGER

  $(function() {
      $("#button-bg").click(function() {
          $("body").css({
              "background": "url('assets/img/bg5.jpg')repeat"
          });
          saveBgCss("url('assets/img/bg5.jpg')repeat");
      });
      $("#button-bg2").click(function() {
          $("body").css({
              "background": "url('assets/img/bg2.jpg')repeat"
          });
          saveBgCss("url('assets/img/bg2.jpg')repeat");
      });


      $("#button-bg3").click(function() {
          $("body").css({
              "background": "url('assets/img/bg.jpg')repeat"
          });
          saveBgCss("url('assets/img/bg.jpg')repeat");
      });

      $("#button-bg5").click(function() {
          $("body").css({
              "background": "url('assets/img/giftly.png')repeat"
          });
          saveBgCss("url('assets/img/giftly.png')repeat");
      });

      $("#button-bg6").click(function() {
          $("body").css({
              "background": "#2c3e50"
          });
          saveBgCss("#2c3e50");
      });

      $("#button-bg7").click(function() {
          $("body").css({
              "background": "url('assets/img/bg3.png')repeat"
          });
          saveBgCss("url('assets/img/bg3.png')repeat");
      });
      $("#button-bg8").click(function() {
          $("body").css({
              "background": "url('assets/img/bg8.jpg')repeat"
          });
          saveBgCss("url('assets/img/bg8.jpg')repeat");
      });
      $("#button-bg9").click(function() {
          $("body").css({
              "background": "url('assets/img/bg9.jpg')repeat"
          });
          saveBgCss("url('assets/img/bg9.jpg')repeat");
      });

      $("#button-bg10").click(function() {
          $("body").css({
              "background": "url('assets/img/bg10.jpg')repeat"
          });
          saveBgCss("url('assets/img/bg10.jpg')repeat");
      });
      $("#button-bg11").click(function() {
          $("body").css({
              "background": "url('assets/img/bg11.jpg')repeat"
          });
          saveBgCss("url('assets/img/bg11.jpg')repeat");
      });
      $("#button-bg12").click(function() {
          $("body").css({
              "background": "url('assets/img/bg12.jpg')repeat"
          });
          saveBgCss("url('assets/img/bg12.jpg')repeat");
      });

      $("#button-bg13").click(function() {
          $("body").css({
              "background": "url('assets/img/bg13.jpg')repeat"
          });
          saveBgCss("url('assets/img/bg13.jpg')repeat");
      });

      // 从cookie取出上次保存的样式
      var bgCss = getBgCss();
      if(bgCss) {
          $("body").css("background", bgCss);
      }
      /**
       * Background Changer end
       */
  });

//TOGGLE CLOSE
    $('.nav-toggle').click(function() {
        //get collapse content selector
        var collapse_content_selector = $(this).attr('href');

        //make the collapse content to be shown or hide
        var toggle_switch = $(this);
        $(collapse_content_selector).slideToggle(function() {
            if ($(this).css('display') == 'block') {
                //change the button label to be 'Show'
                toggle_switch.html('<span class="entypo-minus-squared"></span>');
            } else {
                //change the button label to be 'Hide'
                toggle_switch.html('<span class="entypo-plus-squared"></span>');
            }
        });
    });


    $('.nav-toggle-alt').click(function() {
        //get collapse content selector
        var collapse_content_selector = $(this).attr('href');

        //make the collapse content to be shown or hide
        var toggle_switch = $(this);
        $(collapse_content_selector).slideToggle(function() {
            if ($(this).css('display') == 'block') {
                //change the button label to be 'Show'
                toggle_switch.html('<span class="entypo-up-open"></span>');
            } else {
                //change the button label to be 'Hide'
                toggle_switch.html('<span class="entypo-down-open"></span>');
            }
        });
        return false;
    });
    //CLOSE ELEMENT
    $(".gone").click(function() {
        var collapse_content_close = $(this).attr('href');
        $(collapse_content_close).hide();



    });

//tooltip
    $('.tooltitle').tooltip();

var cookie = {
    set:function(key,val,time){//设置cookie方法
        var date=new Date(); //获取当前时间
        var expiresDays=time;  //将date设置为n天以后的时间
        date.setTime(date.getTime()+expiresDays*24*3600*1000); //格式化为cookie识别的时间
        document.cookie=key + "=" + val +";expires="+date.toGMTString();  //设置cookie
    },
    get:function(key){//获取cookie方法
        /*获取cookie参数*/
        var getCookie = document.cookie.replace(/[ ]/g,"");  //获取cookie，并且将获得的cookie格式化，去掉空格字符
        var arrCookie = getCookie.split(";")  //将获得的cookie以"分号"为标识 将cookie保存到arrCookie的数组中
        var tips;  //声明变量tips
        for(var i=0;i<arrCookie.length;i++){   //使用for循环查找cookie中的tips变量
            var arr=arrCookie[i].split("=");   //将单条cookie用"等号"为标识，将单条cookie保存为arr数组
            if(key==arr[0]){  //匹配变量名称，其中arr[0]是指的cookie名称，如果该条变量为tips则执行判断语句中的赋值操作
                tips=arr[1];   //将cookie的值赋给变量tips
                break;   //终止for循环遍历
            }
        }
        return tips;
    },
    delete:function(key){ //删除cookie方法
        var date = new Date(); //获取当前时间
        date.setTime(date.getTime()-10000); //将date设置为过去的时间
        document.cookie = key + "=v; expires =" +date.toGMTString();//设置cookie
    }
}
/**
 * 将所选的背景主题保存与cookie之中,30天有效期，以便页面刷新之时可以在cookie取出
 */
function saveBgCss(bgCss) {
    bgCss = $.base64.btoa(bgCss);
    cookie.set("bgCss", bgCss, 30);
}

function getBgCss() {
    var bgCss = cookie.get("bgCss");
    if(bgCss) {
        bgCss = $.base64.atob(bgCss);
    }
    return bgCss;
}
 